import instance from '../utils/request'
import { Message } from 'element-ui'

// User修改提交
async function editStudent (student) {
  return await instance({
    url: 'student',
    method: 'put',
    data: student
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('修改失败,服务器错误!')
  })
}

// User修改提交
async function addStudent (student) {
  return await instance({
    url: 'student',
    method: 'post',
    data: student
  }).then(res => {
    return res
  }).catch(() => {
    Message.error('修改失败,服务器错误!')
  })
}

// 得到所有宿管
async function getStudent (page, limit, search) {
  return await instance.get('/student/getStudents?page=' + page + '&limit=' + limit + '&name=' + search).then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}

// 得到所有宿管
async function getStudentIds () {
  return await instance.get('/student').then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}

// 得到所有宿管
async function getStudentAllIds () {
  return await instance.get('/student/all').then(data => {
    return data
  }).catch(() => {
    Message.error('没有权限,请先登录')
  })
}

// 删除宿管
async function deleteStudent (studentId) {
  return await instance.delete('/student/' + studentId).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

// 删除宿管
async function deleteAllStudent (studentId) {
  return await instance.delete('/student/all/' + studentId).then(res => {
    return res
  }).catch(() => {
    Message.error('删除失败,服务器错误!')
  })
}

export default {
  editStudent,
  getStudent,
  deleteStudent,
  deleteAllStudent,
  addStudent,
  getStudentIds,
  getStudentAllIds
}
